Take a set of XY tuples in the form of an UintArray. [x1, y1, x2, y2, x3, y3, ..]
Compare it to another set:
The sets are equivalent if the XY tuples move index in the array: [x1, y1, x2, y2] = [x2, y2, x1, y1]
The sets are NOT equivalent if the XY tuples are not the same:
[x1, y1, x2, y2] = [x1, y1, x3, y3]
To compare quickly a Hashing method is used:
Take a set and reduce each tuple to a single int (same number of states):reduceToSingle([x1, y1, x2, y2, x3, y3, ...]) => [t1, t2, t3, ...]
Take this new array and calculate the cum sum and cum mult of every element:
[t1, t2, t3, ...] => t1 + t2 + t3
[t1, t2, t3, ...] => t1 * t2 * t3
If two sets are equivalent per the rules above, them the cum sums and cum mults are equal:
cumSum([x1, y1, x2, y2]) = cumSum([x2, y2, x1, y1])
cumMult([x1, y1, x2, y2]) = cumMult([x2, y2, x1, y1])
If both are true then the sets are equivalent
cumSum is very fast to compute (compared to elementwise) and can be used as a hash of the set
cumMult is too slow
Output in console